<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./WEB-INF/templates/template.xhtml">

            <ui:define name="content">
                <f:loadBundle basename="org.inftel.scrum.message.Messages" var="msg"/>
                <p:growl id="growl" life="3000"/>
                <div class="grid_6">
                    <!-- Proyectos del usuario -->

                    <div class="grid_4 alpha">
                        <h2 class="gradient"><span></span>#{msg.mainprojects}</h2>
                    </div>
                    <div class="grid_12 omega">
                        <div class="form-item" style="text-align: right">
                            <h:form>
                                <p:commandLink value="#{msg.mainlinkadd}" onclick="dlg.show()"/>
                            </h:form>
                            <p:dialog widgetVar="dlg" modal="true" resizable="false" styleClass="prime-component" header="#{msg.mainlinkadd}">
                                <div class="form-item">
                                    <h:form id="create">
                                        <h:panelGrid styleClass="table" columns="2" style="margin-bottom:10px">
                                            <h:outputLabel for="dlg_name" value="#{msg.mainprojectname}" />
                                            <h:inputText id="dlg_name" value="#{projectBean.name}" required="true"/>
                                            <h:outputLabel for="dlg_description" value="#{msg.mainprojectdescription}" />  
                                            <h:inputTextarea id="dlg_description" style="color: #555;" cols="30" rows="3" 
                                                             value="#{projectBean.description}" required="true"/>
                                            <h:outputLabel for="dlg_initialdate" value="#{msg.mainprojectinitialdate}" />  
                                            <h:inputText id="dlg_initialdate" value="#{projectBean.initialDate}" 
                                                         required="true">
                                                <f:convertDateTime type="date" dateStyle="short"/>
                                            </h:inputText>
                                            <h:outputLabel for="dlg_enddate" value="#{msg.mainprojectenddate}" />  
                                            <h:inputText id="dlg_enddate" value="#{projectBean.endDate}"
                                                         required="true">
                                                <f:convertDateTime type="date" dateStyle="short"/>
                                            </h:inputText>
                                        </h:panelGrid>
                                        <p:commandButton id="submitButton" value="Create" oncomplete="dlg.hide();" styleClass="button"
                                                         update=":growl :projectList :actions :infoProject :sprintAction :sprint :update dlg_name dlg_description dlg_initialdate dlg_enddate :create-sprint" 
                                                         actionListener="#{projectBean.createProject}"/>
                                    </h:form>
                                </div>
                            </p:dialog>
                        </div>
                    </div>
                    <div class="clear"></div>
                    <div class="box">
                        <div class="form-item">
                            <h:form id="projectList">
                                <h:dataTable value="#{projectListBean.activeProjects}" var="project"
                                             binding="#{selectedProjectBean.projectTable}" styleClass="table">
                                    <h:column>
                                        <h:outputText value="#{project.name}"/>
                                    </h:column>
                                    <h:column>
                                        <h:commandLink value="#{msg.mainselectproject}" action="#{selectedProjectBean.select()}">
                                            <f:ajax execute="@this" render=":infoProject :actions :sprintAction :sprint :update :create-sprint"/>
                                        </h:commandLink>
                                    </h:column>
                                </h:dataTable>
                            </h:form>
                        </div>
                    </div>
                </div>
                <div class="grid_10">
                    <!-- Información del proyecto seleccionado -->

                    <div class="grid_8 alpha"><h2>#{msg.mainprojectinfo}</h2></div>
                    <div class="grid_8 omega">
                        <div class="form-item" style="text-align: right">
                            <h:form id="actions">
                                <h:link value="#{msg.mainlinkaddusers}" rendered="#{selectedProjectBean.selected and selectedProjectBean.owner == loginBean.user}" outcome="#{selectedProjectBean.addUsers()}"/>
                                <p:commandLink value="#{msg.mainlinkmodify}" rendered="#{selectedProjectBean.selected and selectedProjectBean.owner == loginBean.user}" onclick="dlgUpdate.show();" />
                                <p:commandLink value="#{msg.mainlinkdelete}" rendered="#{selectedProjectBean.selected and selectedProjectBean.owner == loginBean.user}" onclick="dlgDelete.show();"/>
                            </h:form>
                            <p:dialog widgetVar="dlgUpdate" modal="true" resizable="false" styleClass="prime-component" header="#{msg.mainlinkmodify}">
                                <div class="form-item">
                                    <h:form id="update">
                                        <h:panelGrid styleClass="table" columns="2" style="margin-bottom:10px">
                                            <h:outputLabel for="dlgUpdate_name" value="#{msg.mainprojectname}" />
                                            <h:inputText id="dlgUpdate_name" value="#{selectedProjectBean.name}" required="true"/>
                                            <h:outputLabel for="dlgUpdate_description" value="#{msg.mainprojectdescription}" />  
                                            <h:inputTextarea id="dlgUpdate_description" style="color: #555;" cols="30" rows="3" 
                                                             value="#{selectedProjectBean.description}" required="true"/>
                                            <h:outputLabel for="dlgUpdate_initialdate" value="#{msg.mainprojectinitialdate}" />  
                                            <h:inputText id="dlgUpdate_initialdate" value="#{selectedProjectBean.initialDate}" 
                                                         required="true">
                                                <f:convertDateTime type="date" dateStyle="short"/>
                                            </h:inputText>
                                            <h:outputLabel for="dlgUpdate_enddate" value="#{msg.mainprojectenddate}" />  
                                            <h:inputText id="dlgUpdate_enddate" value="#{selectedProjectBean.endDate}"
                                                         required="true">
                                                <f:convertDateTime type="date" dateStyle="short"/>
                                            </h:inputText>
                                        </h:panelGrid>
                                        <p:commandButton id="updateButton" value="Update" oncomplete="dlgUpdate.hide();" styleClass="button"
                                                         update=":growl :projectList :actions :infoProject :sprintAction :sprint" 
                                                         actionListener="#{selectedProjectBean.updateProject()}"/>
                                    </h:form>
                                </div>
                            </p:dialog>
                            <p:dialog widgetVar="dlgDelete" modal="true" resizable="false" styleClass="prime-component" header="#{msg.mainlinkdelete}">
                                <div class="form-item">
                                    <h:form id="delete">
                                        <h5>Are you sure to delete this project?</h5>
                                        <p:commandButton id="deleteButton" value="Yes" oncomplete="dlgDelete.hide();" styleClass="button"
                                                         update=":growl :projectList :actions :infoProject :sprintAction :sprint" 
                                                         action="#{selectedProjectBean.deleteProject()}" ajax="false"/>
                                        <span style="width: 20px;"></span>
                                        <p:commandButton id="cancelButton" value="Cancel" styleClass="button" onclick="dlgDelete.hide();"/>
                                    </h:form>
                                </div>
                            </p:dialog>
                        </div>
                    </div>
                    <div class="clear"></div>
                    <div class="box">
                        <h:form id="infoProject">
                            <p><h:outputText value="No selected project" rendered="#{!selectedProjectBean.selected}"/></p>
                            <h:panelGrid style="margin-left: 10px" styleClass="table" rendered="#{selectedProjectBean.selected}">
                                <h:outputLabel styleClass="bold" value="#{msg.mainprojectname}" for="projectName" />
                                <h:outputText id="projectName" value="#{selectedProjectBean.name}"/>
                            </h:panelGrid>
                            <h:panelGrid style="margin-left: 10px" columns="3" styleClass="table" rendered="#{selectedProjectBean.selected}">
                                <h:outputLabel styleClass="bold" value="#{msg.mainprojectowner}" for="owner" />
                                <h:outputLabel styleClass="bold" value="#{msg.mainprojectinitialdate}" for="initialDate" />
                                <h:outputLabel styleClass="bold" value="#{msg.mainprojectenddate}" for="endDate" />
                                <h:outputText id="owner" value="#{selectedProjectBean.owner.name} #{selectedProjectBean.owner.surname}"/>
                                <h:outputText id="initialDate" value="#{selectedProjectBean.initialDate}">
                                    <f:convertDateTime type="date" dateStyle="long"/>
                                </h:outputText>    
                                <h:outputText id="endDate" value="#{selectedProjectBean.endDate}">
                                    <f:convertDateTime type="date" dateStyle="long"/>
                                </h:outputText>
                            </h:panelGrid>
                            <h:panelGrid style="margin-left: 10px" styleClass="table" rendered="#{selectedProjectBean.selected}">
                                <h:outputLabel styleClass="bold" value="#{msg.mainprojectdescription}" for="projectDescription" />
                                <h:outputText id="projectDescription" value="#{selectedProjectBean.description}"/>
                            </h:panelGrid>
                        </h:form>
                    </div>
                    <div class="separator_20"></div>
                    <!-- Sprints del proyecto seleccionado -->

                    <div class="grid_8 alpha">
                        <h2>#{msg.mainsprintsinfo}</h2>
                    </div>
                    <div class="grid_8 omega">
                        <div class="form-item" style="text-align: right">
                            <h:form id="sprintAction">
                                <p:commandLink value="#{msg.mainaddnewSprint}" onclick="dlgCreateSprint.show()"
                                               rendered="#{selectedProjectBean.selected and selectedProjectBean.owner == loginBean.user}"/>
                            </h:form>
                        </div>

                        <p:dialog widgetVar="dlgCreateSprint" modal="true" resizable="false" styleClass="prime-component" header="#{msg.createSprintTitle}">
                            <div class="form-item">
                                <h:form id="create-sprint" style="text-align: right">
                                    <h:panelGrid  styleClass="table" columns="2" style="margin-bottom:10px">  

                                        <h:outputLabel value="#{msg.createSprintFieldSprintNumber}"/>
                                        <p:inputText value="#{sprintBean.sprintNumber}"/>  

                                        <h:outputLabel value="#{msg.createSprintFieldInitDate}"/>
                                        <p:calendar id="InitialDate" value="#{sprintBean.initialDate}" mindate="#{sprintBean.actualDate}" maxdate="#{selectedProjectBean.endDate}"/>  

                                        <h:outputLabel value="#{msg.createSprintFieldEndDate}"/>
                                        <p:calendar id="EndDate" value="#{sprintBean.endDate}" mindate="#{sprintBean.actualDate}" maxdate="#{selectedProjectBean.endDate}"/>  

                                        <h:outputLabel value="#{msg.createSprintFieldPathProject}"/>
                                        <p:inputText value ="#{sprintBean.projectPath}" required="false"/>  

                                    </h:panelGrid>
                                    <p:commandButton id="createSprintButton" value="#{msg.createSprintButtonCreate}"  actionListener="#{sprintBean.createSprint()}" oncomplete="dlgCreateSprint.hide();" styleClass="button" update=":growl :sprint"/> 
                                </h:form>
                            </div>
                        </p:dialog>

                    </div>
                    <div class="clear"></div>
                    <div class="box">
                        <div class="form-item">
                            <h:form id="sprint" >
                            <p><h:outputText value="No selected project" rendered="#{!selectedProjectBean.selected}"/></p>
                            <p><h:outputText value="This project has not sprints" rendered="#{selectedProjectBean.selected and selectedProjectBean.sprints.size() == 0}"/></p>
                            <h:dataTable value="#{selectedProjectBean.sprints}" styleClass="table"
                                         var="sprint" rendered="#{selectedProjectBean.selected and selectedProjectBean.sprints.size() > 0}"
                                         binding="#{selectedSprintBean.sprintTable}">
                                
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{msg.createSprintFieldSprintNumber}"/>
                                    </f:facet>
                                    <h:outputText value="Sprint #{sprint.sprintNumber}"/>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{msg.createSprintFieldInitDate}"/>
                                    </f:facet>
                                    <h:outputText value="#{sprint.initialDate}">
                                        <f:convertDateTime type="date" dateStyle="medium"/>
                                    </h:outputText>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{msg.createSprintFieldInitDate}"/>
                                    </f:facet>
                                    <h:outputText value="#{sprint.endDate}">
                                        <f:convertDateTime type="date" dateStyle="medium"/>
                                    </h:outputText>
                                </h:column>
                                <h:column>
                                    <h:commandLink value="View sprint" action="#{selectedSprintBean.viewPanel()}"/>
                                </h:column>
                                <h:column>
                                    <h:commandLink value="#{msg.mainTask}" action="#{selectedSprintBean.createTask()}" rendered="#{selectedProjectBean.owner == loginBean.user}"/>
                                </h:column>
                                <h:column>
                                    <p:commandLink value="Delete" actionListener="#{selectedSprintBean.selectSprint()}" onsuccess="dlgDeleteSprint.show();" rendered="#{selectedProjectBean.owner == loginBean.user}"/>
                                </h:column>
                                
                            </h:dataTable>                            
                            </h:form>
                            <p:dialog widgetVar="dlgDeleteSprint" modal="true" resizable="false" styleClass="prime-component" header="Delete sprint">
                                <div class="form-item">
                                    <h:form id="delete-sprint" style="text-align: right">
                                        <h5>Are you sure to delete this sprint?</h5>
                                        <p:commandButton id="deleteSprintButton" value="Yes" oncomplete="dlgDeleteSprint.hide();" styleClass="button"
                                                         update=":growl :projectList :actions :infoProject :sprintAction :sprint" 
                                                         action="#{selectedSprintBean.deleteSprint()}" ajax="false"/>
                                        <span style="width: 20px;"></span>
                                        <p:commandButton id="cancelSprintButton" value="Cancel" styleClass="button" onclick="dlgDeleteSprint.hide();"/>
                                    </h:form>
                                </div>
                            </p:dialog>
                        </div>
                    </div>
                </div>
                <div class="clear"></div>
                <div class="separator_10"></div>

            </ui:define>

        </ui:composition>

    </body>
</html>
